public class PrimeEliminatedFinder {
	boolean[] primes = null;
	
	public PrimeEliminatedFinder(int n)
	{
		primes = new boolean[n+1];
		
		for (int i=0; i<=n; i++)
			primes[i] = true;
	}
	
	public void calculatePrimes()
	{
		// 0 and 1 is not a prime
		primes[0] = primes[1] = false;
		
		// Check for prime until sqrt(n)
		int sqrt = (int) Math.sqrt(primes.length-1);		
		for (int i=2; i<=sqrt; i++)
		{
			// If i is not prime, go for next number
			if (primes[i] == false)
				continue;
			
			// i is a prime
			int next = i+i;
			while (next < primes.length)
			{
				primes[next] = false;
				next += i;
			}
		}
	}
	
	public boolean[] getPrimesArray()
	{
		return primes;
	}
	
	public String toString()
	{
		StringBuffer str = new StringBuffer();
		
		for (int i=0; i<primes.length; i++)
			if (primes[i])
				str.append(i + " ");
		
		return str.toString();
	}
}
